package com.tz.config;

import com.tz.entity.CPU;
import com.tz.entity.MainBoard;
import com.tz.entity.Memory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by yejf on 2017/1/6.
 * 此类通过 @Bean 注解来初始化一些Bean,并给这些Bean赋值初始值，并做为其它的Bean的注入
 */
@Configuration //spring容器的配置类
@ComponentScan("com.tz.entity")  //
public class CodeConfigForDI {

    @Bean
    public CPU cpu() {
        return new CPU(100L,"Intel",2.7d);
    }

    @Bean
     public Memory m1(){
        return new Memory(50L,4,"泛型优先1");
    }

    @Bean
    public Memory m2(){
        return new Memory(60L,8,"泛型优先2");
    }

    @Bean  //相当于在applicationContext.xml文件中添加一个 bean, id为 memories
    public List<Memory> memories() {
        //
        List<Memory> memories = new ArrayList<>();
        Memory m1 = new Memory(50L,4,"DDR3");
        Memory m2 = new Memory(60L,8,"DDR4");
        //
        memories.add(m1);
        memories.add(m2);
        //返回
        return memories;
    }

    @Bean(name = "board")
    public MainBoard mainBoard() {
        return new MainBoard(11L, "华硕");
    }

}
